import { defineConfig } from 'umi';
import CompressionPlugin from 'compression-webpack-plugin'

const isProd = process.env.NODE_ENV === 'production'
export default defineConfig({
  links: [{ rel: 'icon', href: './favicon.ico' }],
  extraBabelPlugins: [isProd ? 'transform-remove-console' : ''],
  chainWebpack(config: any) {
    config.module.rule('file')
      .test(/.docx|doc|pdf|xls|xlsx$/)
      .use('file-loader')
      .loader('file-loader')
    if (isProd) {
      config.plugin('compression-webpack-plugin').use(CompressionPlugin, [
        // @ts-ignore
        {
          test: /\.(js|css|html)$/i, // 匹配
          threshold: 10240, // 超过10k的文件压缩
          deleteOriginalAssets: false, // 不删除源文件
        },
      ])
    }
  },
  headScripts: [
    {
      type: 'text/javascript',
      charset: 'utf-8',
      src: 'https://gw.alipayobjects.com/os/rmsportal/xsxusXNIcXwiGqtNiyOd.js',
      // @ts-ignore
      chat_url: 'https://cschat.antcloud.com.cn/index.htm',
      logo_src: '/CustomerSupport.png',
      logo_position: 'rm',
      tntInstId: 'dqe_08ia&scene=SCE01217624',
    },
  ],
  define: {
    BASE_URL_IMAGE: '/images', // 前缀地址-图片
    BASE_URL_API: '', // 前缀地址-接口请求
  },
  proxy: {
    '/api': {
      target: 'http://192.168.57.16:64464',
      changeOrigin: true,
      pathRewrite: { '^': '' },
    },
    '/images': {
      target: 'http://192.168.57.16:64464',
      changeOrigin: true,
      pathRewrite: { '^/images': '/' },
    },
  },
  dva: {
    immer: true,
    hmr: false,
    disableModelsReExport: true,
  },
  theme: {
    '@primary-color': '#1A3DC9',
  },
  locale: {
    default: 'zh-CN',
    antd: true,
    title: false,
    baseNavigator: true,
    baseSeparator: '-',
  },
  dynamicImport: {
    loading: '@/Loading',
  },
  cssLoader: {
    localsConvention: 'camelCase',
  },
  nodeModulesTransform: {
    type: 'none',
  },
  fastRefresh: {},
  mfsu: {},
  webpack5: {},
  antd: {
    dark: false, // 开启暗色主题
    // compact: true, // 开启紧凑主题
  },
});
